$(function(){
	
	$("TITLE").html($("#title").html());
	if($("IMG").attr("src") == "") $("IMG").remove();
	
	var number = $("#persons_number").html() - 0;  
	var diameter = $("#diameter_number").html() - 0;
	
	$("#persons_number").html("<INPUT TYPE=\"number\" VALUE=\"" + number + "\"></INPUT>"); 
	$("#diameter_number").html("<INPUT TYPE=\"number\" VALUE=\"" + diameter + "\"></INPUT>");
	
	$("#ingredients p").each(function(){
		var value = $(this).children("span:first-child").html() - 0;
		$(this).children("span:first-child").addClass("amount");
		$(this).children("span:first-child").hide();
		$(this).prepend("<SPAN class=\"number\">" + value + "</SPAN>");
	});
	
	$("#persons_number input").change(function(){
		var newNumber = $("#persons_number input").val() - 0;
		
		var factor = newNumber/number;
		
		$("#ingredients p").each(function(){
			var value = $(this).children(".amount").html() - 0;
			console.log(value, factor);
			$(this).children(".number").html(Math.round(value * factor *100)/100);
		});
	});
  
  $("#diameter_number input").change(function(){
		var newDiameter = $("#diameter_number input").val() - 0;
		
		var factor = Math.pow(0.5 * newDiameter, 2) / Math.pow(0.5 * diameter, 2);
		
		$("#ingredients p").each(function(){
			var value = $(this).children(".amount").html() - 0;
			console.log(value, factor);
			$(this).children(".number").html(Math.round(value * factor *100)/100);
		});
	});
	
});